package com.dragon.client.controller.supplies;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.common.model.ResponseData;
import com.dragon.logical.service.supplies.IStockService;
import com.dragon.repository.domain.dto.StockDTO;
import com.dragon.repository.entity.Stock;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 库存表 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-11-13
 */
@RestController
@RequestMapping("stock")
@Api(tags = "库存")
public class StockController {

    @Autowired
    IStockService service;

    @GetMapping("list")
    @ApiOperation(value = "库存列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", required = true, type = "int"),
            @ApiImplicitParam(name = "limit", value = "条数", required = true, type = "int"),
            @ApiImplicitParam(name = "search", value = "搜索参数", required = false, type = "string"),
            @ApiImplicitParam(name = "warehouseId", value = "仓库id", required = false, type = "int"),
            @ApiImplicitParam(name = "categoryId", value = "类别id", required = false, type = "int")
    })
    public ResponseData<List<StockDTO>> listStock(@RequestParam Integer page,
                                                  @RequestParam Integer limit,
                                                  @RequestParam(required = false) String search,
                                                  @RequestParam(required = false) Integer warehouseId,
                                                  @RequestParam(required = false) Integer categoryId){
        Page<Stock> stockPage = service.stockList(page, limit, search, warehouseId, categoryId);
        return ResponseData.success(StockDTO.convertList(stockPage.getRecords()),stockPage.getTotal());
    }

}
